 import {stringify} from '@/common/common';
import {getQueryString} from '@/common/common'
 const ListMixin = {
    data(){
        return {
            queryParam:{},//查询条件
			list:[],//数据集合
            // 分页,mescroll 配置
			pageOption:{
				num: 1,
				size: 10
			}
        }
    },
    onLoad(){
    },
	
	computed: {
		top() {
			return this.CustomBar  + 92
		},
	},
    methods: {
		/**
		 * 
		 * @param {string} url 
		 * 预览图片
		 */
		previewImage(url) {
			if(url){
				uni.previewImage({
				  current: url.replace(/\\/g,'/'),
				  urls: [url.replace(/\\/g,'/')],
				  indicator: true
				});
			}
		  },
		/**
		 * @param {obj} item
		 * 获取纯图片集合
		 */
		
		 getImages(item){
			let images = item.fileList.split(',').map(v=>v.replace(/\\/g,'/'))
			return images
		},
        /**
         * 组装参数
         */
        getQueryParams(){
            let params = Object.assign({},this.queryParam)
			return params
        },
        search(){
			this.pageOption.num = 1
			this.list = []
			this.loadData(this.pageOption)
		},
		/**
		 * 
		 * @param {number} page 
		 * 获取列表数据
		 */
         loadData(page) {
			let params = {
				pageNum: page.num,
				pageSize: page.size
			}
			params = Object.assign(params,this.getQueryParams())
			//联网加载数据
			this.$u.api[this.url.list](params).then(res => {
				//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
				let data = res.data.list
				//设置列表数据
				if (res.code == 200) {
					for (let annItem of data) {
						this.list.push(annItem)
					}
				}
				if (page.num == 1) {
					this.list = []; //如果是第一页需手动制空列表
					this.list = this.list.concat(res.data.list); //追加新数据
				}
				this.mescroll.endBySize(data.length,res.data.total);
			}).catch(() => {
				//联网失败, 结束加载
				this.mescroll.endErr();
			})
		},
		navTo(url,item) {
			let query = stringify(item)
			uni.navigateTo({
				url: `${url}?${query}` 
			});
		},
		
		/**@拨打电话
		 * @param {Object} item
		 */
		callPhone(item){
			if(!item.phone) return;
			wx.makePhoneCall({
			  phoneNumber: item.phone,
			  success: function(res) {
			    console.log('拨打电话成功！');
			  },
			  fail: function(res) {
			    console.log('拨打电话失败！');
			  }
			})
		}
    },
}
export default ListMixin